function StoreAssistant() {
	/* this is the creator function for your scene assistant object. It will be passed all the 
	   additional parameters (after the scene name) that were passed to pushScene. The reference
	   to the scene controller (this.controller) has not be established yet, so any initialization
	   that needs the scene controller should be done in the setup function below. */
}

StoreAssistant.prototype.setup = function() {
	/* this function is for setup tasks that have to happen when the scene is first created */
		
	/* use Mojo.View.render to render view templates and add them to the scene, if needed. */
	
	/* setup widgets here */
	
	/* add event handlers to listen to events from widgets */
	this.CommandMenuAttributes = {
										spacerHeight: 25,
										menuClass: 'no-fade',
									 };
		
		this.CommandMenuModel = {
									visible: true,
									items: [{}, {
									  		items: [{
													label: 'Done',
													command: 'done'
												}]
											}, {}
											]
								};
	this.controller.setupWidget(Mojo.Menu.commandMenu, this.CommandMenuAttributes, this.CommandMenuModel); 
	this.controller.listen('coolerBox', Mojo.Event.tap, this.cooler_tap.bindAsEventListener(this)); 
	this.controller.listen('storageBox', Mojo.Event.tap, this.storage_tap.bindAsEventListener(this)); 
	var t = setInterval(engine, 50);
}

function engine(){
	if (coolerLevel + 1 <= 6) {
		$(coolerText).innerHTML = "Cooler &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp $" + (coolerLevel + 1) * 5 + ".00";
	}else{
		$(coolerText).innerHTML = "Cooler &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp N/A"
	}
	$(storageText).innerHTML = "Extra Storage &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp $" + storagePrice + (15 + (storageLevel * 2)); 
}

StoreAssistant.prototype.cooler_tap = function(event){
	storeSelected = "cooler";
    this.controller.showDialog({
    	template: 'store/cooler-scene',
        assistant:new CoolerDialogAssistant(this),
        preventCancel:false
    });

}

StoreAssistant.prototype.storage_tap = function(event){
	storeSelected = "storage";
    this.controller.showDialog({
    	template: 'store/cooler-scene',
        assistant:new CoolerDialogAssistant(this),
        preventCancel:false
    });

}

StoreAssistant.prototype.activate = function(event) {
	/* put in event handlers here that should only be in effect when this scene is active. For
	   example, key handlers that are observing the document */
}


StoreAssistant.prototype.deactivate = function(event) {
	/* remove any event handlers you added in activate and do any other cleanup that should happen before
	   this scene is popped or another scene is pushed on top */
}

StoreAssistant.prototype.cleanup = function(event) {
	/* this function should do any cleanup needed before the scene is destroyed as 
	   a result of being popped off the scene stack */
}

function dayStart(){
	dayNumber++;
	//numberOfLemons = 1;
	//numberOfSuger = 1;
	//numberOfCups = 1;
	//numberOfAds = 1;
	priceOfAds = 0.15;
	//price = 0.01;
	//pricePerCup = 0.11;
	//expenses = 0.11;
	chanceOfRain = 0;
	temperature = 0;
	messageTrue = false;
	sugerMessage = "";
	sugerGood = false;
	cupsSoldNumber = 0;
	if (dayNumber <= numberOfDays){
		Mojo.Controller.stageController.swapScene('day');
	}else if (dayNumber > numberOfDays){
		Mojo.Controller.stageController.swapScene('end');
	}
}

StoreAssistant.prototype.handleCommand = function (event) {
	this.controller=Mojo.Controller.stageController.activeScene();
    if (event.type == Mojo.Event.commandEnable &&
	    (event.command == Mojo.Menu.helpCmd)) {
         event.stopPropagation(); // enable help. now we have to handle it
    }
	 if (event.type == Mojo.Event.commandEnable &&
	    (event.command == Mojo.Menu.prefsCmd)) {
         event.stopPropagation(); // enable help. now we have to handle it
    }

	console.log("RIGHT HERE");
	if (event.type == Mojo.Event.command) {
		var youOrdered = "";
		console.log("SettingsSceneAssistant::handleCommand(): Got command: " + event.command);
		switch (event.command) {
			
			// another built-in menu item, but we've enabled it (see below in this method)
			// so now we have to handle it:
			case Mojo.Menu.helpCmd:
				Mojo.Controller.stageController.pushScene('support');
				break;
				
			case Mojo.Menu.prefsCmd:
				Mojo.Controller.stageController.pushScene('settings');
				break;
			case "done":
				dayStart();
				break;
		}
	}	
}
var CoolerDialogAssistant = Class.create({
	
	initialize: function(sceneAssistant) {
		this.sceneAssistant = sceneAssistant;
		this.controller = sceneAssistant.controller;
	},
	
	setup : function(widget) {
		if (storeSelected == "storage"){
			$(image).innerHTML = "<img src='images/storage.png' height='150' width='100'/>"
		}else if (storeSelected == "cooler"){
			$(image).innerHTML = "<img src='images/cooler.png' height='150' width='100'/>"
		}
		this.widget = widget;
		if (storeSelected == "cooler"){
			if (coolerLevel + 1 <= 6) {
				this.controller.setupWidget('close', {}, {buttonLabel: 'Buy', buttonClass:"affirmative"});
				this.callFinish = this.finish.bind(this)
				Mojo.Event.listen(this.controller.get('close'),Mojo.Event.tap, this.callFinish);
			}else{
				this.controller.setupWidget("close",
	        	this.attributes = {},
	        	this.model = {
		            label : "Buy",
		            disabled: true,
					buttonClass: "affirmative"
	        });

			}
		}else if (storeSelected == "storage"){
			if (storageLevel + 1 <= 5) {
				this.controller.setupWidget('close', {}, {buttonLabel: 'Buy', buttonClass:"affirmative"});
				this.callFinish = this.finish.bind(this)
				Mojo.Event.listen(this.controller.get('close'),Mojo.Event.tap, this.callFinish);
			}else{
				this.controller.setupWidget("close",
	        	this.attributes = {},
	        	this.model = {
		            label : "Buy",
		            disabled: true,
					buttonClass: "affirmative"
	        });

			}
		}
		
		this.controller.setupWidget('ok', {}, {buttonLabel: 'Ok', buttonClass:"affirmative"});	
		this.callClose = this.close.bind(this)
		Mojo.Event.listen(this.controller.get('ok'),Mojo.Event.tap, this.callClose);
	},
	
	activate: function(event){
		if (storeSelected == "cooler") {
			if (coolerLevel + 1 <= 6) 
				$(description).innerHTML = "This is a level " + (coolerLevel + 1) + " cooler for your stand. You can keep your ingrediants in here, so if you make too many cups you won't have to pay for the ones that can fit in this cooler. Capacity: " + (coolerCapacity + 5) + " Cups."
			else {
				$(description).innerHTML = "You already have the highest level cooler";
			}
		}else if (storeSelected == "storage"){
			if (coolerLevel + 1 <= 5) 
				$(description).innerHTML = "This is a level " + (storageLevel + 1) + " storage unit for your stand. This will allow you to store more materials and so it will increase the number of cups you can make. This unit will increase your cups storage to " + (maximumCups + 25) + " Cups."
			else {
				$(description).innerHTML = "You already have the highest level cooler";
			}
		}
	},
	
	finish: function(){
		if (storeSelected == "cooler"){
			if (money - (5 + (coolerLevel + 1)) >= 0){	
				coolerLevel++;
				coolerCapacity += 5;
				money -= (5 + (coolerLevel + 1));
				this.close();
			}else{
				// they don't have enough money so don't let them buy it
				Mojo.Controller.errorDialog("You don't have enough money!");
			}
		}else if (storeSelected == "storage"){
			if (storagePrice + (15 + (storageLevel * 2))){
				storageLevel++;
				maximumCups + 25;
				money -= (storagePrice + (15 + (storageLevel * 2)));
				this.close();
			}else{
				Mojo.Controller.errorDialog("You don't have enough money!");
			}
		}
	},
	
	close: function() {
		Mojo.Event.stopListening(this.controller.get('close'),Mojo.Event.tap, this.finish);
		this.widget.mojo.close();
	}
	
	
});
